﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mani.Common;
using Ghasam.Business.Services;
using Ghasam.Business.Domain.Entity;

public partial class NewAccounting : BasePage
{
    #region "Private Property"
    private IAccountingService accountingService;
    private ICustomerService customerService;
    private int _customerId;
    private int _isFromal;
    private double _debit;
    private double _credit;
    private string _desc;

    #endregion
    public IAccountingService AccountingService
    {
        set { accountingService = value; }
        get { return accountingService; }
    }
    public ICustomerService CustomerService
    {
        set { customerService = value; }
        get { return customerService; }
    }
    public override string ActionName {
        get {
            return "vw_newaccounting";
        }
    }

    protected void Page_Load( object sender, EventArgs e ) {
        CheckCustomerType();
    }
    private void fillCustomerList()
    {
        Customer customer = new Customer();
        checkFormalCustomer();
        customer.IsFormal = Convert.ToBoolean(_isFromal);
        ddlCustomers.DataSource = customerService.GetCustomers(customer, 0, 2000);
        ddlCustomers.DataBind();
    }
    private void CheckCustomerType() {
        divHiddenCustomers.Visible = CommonHelper.ShowHiddenCustomers();
    }

    private void checkFormalCustomer()
    {
        _isFromal = 0;
        bool show = CommonHelper.ShowHiddenCustomers();
        if (show && rbHiddenCustomers.Checked)
        {
            _isFromal = 1;
        }
        else if (show && rbAll.Checked)
        {
            _isFromal = -1;
        }
    }
    private void getControlsValue()
    {
        checkFormalCustomer();
        _desc = txtDesc.Text;
        _credit = Convert.ToDouble(txtCredit.Text);
        _debit = Convert.ToDouble(txtDebit.Text);
        _customerId =Convert.ToInt32(ddlCustomers.SelectedItem.Value);


    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        getControlsValue();
        AccountingService.AccountingSaveOrUpadate(_customerId, Convert.ToBoolean(_isFromal), (float)_debit, (float)_credit, _desc, DateTime.Today.Date, DateTime.Today.Date);
    }


}
